package Internet.Program;

import java.net.InetAddress;

/**
 * @Author: Jason
 * @ClassName: demo1
 * @Description: 线程测试代码，使用synchronized进行同步（解决并发问题）
 * @Package：Internet.Program
 * @Project：javaDemo
 * @name：demo1
 * @Filename：demo1
 **/

public class thread_test{

    public static void main(String[] args) {
        test test = new test();

        new Thread(test).start();
        new Thread(test).start();


    }
}


class test implements Runnable {
    String name;
    int money=100;

    @Override
    public void run() {
        synchronized (this){
            System.out.println(Thread.currentThread().getName()+":"+money--);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println(money);
        }

    }

//    public test(String name) {
//        this.name = name;
//        this.money = money;
//    }
}
